package models;


import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

import columnEditors.JTableRenderer;

public class DBTableModel extends DefaultTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTableRenderer tableRenderer;
	
	public DBTableModel(JTableRenderer tableRenderer, final int buttonColumn) {
		super();

		this.tableRenderer = tableRenderer;
		
		this.addTableModelListener(new TableModelListener() {

			@Override
			public void tableChanged(TableModelEvent e) {
				int row = e.getFirstRow();
				int column = e.getColumn();
				
				if (column > 0 && column < buttonColumn) {
					DBTableModel.this.tableRenderer.addEditedCell(row, column);
				}
				
			}
			
		});
	}
			
	public boolean isCellEditable(int row, int cell){
		if (cell == 0 && row == this.getRowCount() - 1)
			return false;
		
		if (cell != 1)
			return true;
		
		return false;
	}
}
